﻿using FastCloud.Base.Desgin;
using FastCloud.DMP.Entity;
using FastIOC.Attribute;
using FastORM.Entity;
using FastUtil.Data;
using System;
using System.Collections.Generic;
using System.Text;

namespace FastCloud.DMP.DB
{
    public class DB_Column : BaseDBML<Frame_Column>
    {
        public void InsertOnlyInfo(Frame_Column Entity)
        {
            if (string.IsNullOrEmpty(Entity.ColumnGuid))
            {
                Entity.ColumnGuid = GenerateUtil.GenerateUnitGuid();
            }
            Entity.AddDate = DateTime.Now;
            base.Insert(Entity);
        }

        public override void Insert(Frame_Column Entity)
        {
            if (string.IsNullOrEmpty(Entity.ColumnGuid))
            {
                Entity.ColumnGuid = GenerateUtil.GenerateUnitGuid();
            }
            Entity.AddDate = DateTime.Now;
            base.Insert(Entity);
           
        }

        public override void DeleteByID(string UnitGuid)
        {
            base.DeleteByID(UnitGuid);
        }

        public void DeleteByPhysicalColumnName(string PhysicalColumnName)
        {
            base.DeleteByFiled("PhysicalColumnName", PhysicalColumnName);
        }

        public bool ExistColumn(string TableGuid,string PhysicalColumnName)
        {
            List<ParamEntity> ParamList = new List<ParamEntity>() { new ParamEntity() { ParamName = "TableGuid", ParamValue = TableGuid } ,new ParamEntity() { ParamName = "PhysicalColumnName", ParamValue = PhysicalColumnName } };
            string sql = "TableGuid=@TableGuid and PhysicalColumnName=@PhysicalColumnName";
            return SelectCount(sql, ParamList) > 0;
        }

        public List<Frame_Column> SelectColumnByTableGuid(string TableGuid)
        {
            List<ParamEntity> ParamList = new List<ParamEntity>() { new ParamEntity() { ParamName = "TableGuid", ParamValue = TableGuid } };
            string sql = "TableGuid=@TableGuid";
            return SelectList("*", sql, "SortNum desc", ParamList);
        }
    }
}
